<template>
  <page-header-wrapper :title="false">
    <a-card title="废弃合同列表">
      <div class="table-page-search-wrapper">
        <a-form-model :model="queryParam" layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-model-item label="合同编号">
                <a-input v-model="queryParam['filter[contract_no]']" placeholder="请输入合同编号"/>
              </a-form-model-item>
            </a-col>
            <a-col :md="6">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="reset">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <div class="table-operator">
        <s-table
          bordered
          ref="table"
          :row-key="(record) => record.contract_id"
          :columns="contractColumns"
          :data="contractData"
        >
          <template slot="ix" slot-scope="text,record,index">
            {{index + 1}}
          </template>
          <template slot="adviser_name" slot-scope="text, record">
            <a-tag>{{text}}</a-tag><br>
            <a-tag>{{record.group_type}}组</a-tag><br>
            <a-tag>{{record.leader_name}}</a-tag>
          </template>
          <template slot="action" slot-scope="text,record">
            <a-button size="small" type="primary" @click="$router.push({ name: 'ContractDetail', params: { id: record.contract_id } })">查看</a-button>
            <a-button size="small" type="danger" @click="onRecover(record.contract_id)">恢复</a-button>
          </template>
        </s-table>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import financeColumns from '@/columns/finance'
import { getAbandonList, recoverContract } from '@/api/contract'

export default {
  components: {
    STable
  },
  name: 'AbandonContract',
  data () {
    return {
      contractColumns: financeColumns.contract,
      contractData: parameters => {
        return getAbandonList(Object.assign(parameters, this.queryParam)).then(res => {
          this.tabOpts = res.result.tab_opts
          this.statusOpts = res.result.status_opts
          this.adviserOpts = res.result.all_advisers
          this.financeOpts = res.result.all_finances
          return res.result
        })
      },
      queryParam: {},
      advanced: true
    }
  },
  methods: {
    onRecover (id) {
      this.$confirm({
        title: '是否恢复此合同',
        onOk: () => {
          recoverContract(id).then(res => {
            this.$refs.table.refresh(true)
          })
        }
      })
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    reset () {
      this.queryParam = {}
      this.$refs.table.refresh(true)
    }
  }
}
</script>

<style scoped>

</style>
